using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using EIA.PM.Model;
using EIA.PM.DAL;

namespace EIA.PM.BLL
{
    public class TProjectDispatchBlp : ITProjectDispatchBlp
    {
        ITProjectDispatchDao _TProjectDispatchDao = null;
        public TProjectDispatchBlp()
        {
            _TProjectDispatchDao = X.DaoFactory.Create<ITProjectDispatchDao>();
        }

        public int Insert(TProjectDispatch o)
        {
            object r = _TProjectDispatchDao.Insert(o);
			return r is int ? (int)r : 0;
        }

        public IList<int> InsertList(IList<TProjectDispatch> lst)
        {
            _TProjectDispatchDao.DASession.BeginTransaction();
            try
            {
                IList<int> keys = new List<int>();
                foreach (TProjectDispatch o in lst)
                {
                    object r = _TProjectDispatchDao.Insert(o);
                    keys.Add(r is int ? (int)r : 0);
                }
                _TProjectDispatchDao.DASession.CommitTransaction();
                return keys;
            }
            catch
            {
                _TProjectDispatchDao.DASession.RollbackTransaction();
                throw;
            }
        }

        public bool Update(TProjectDispatch o)
        {
            return _TProjectDispatchDao.Update(o);
        }

		public bool UpdateChanged(IDictionary props)
		{
			return _TProjectDispatchDao.Update(props);
		}

        public bool UpdateList(IList<TProjectDispatch> lst)
        {
            _TProjectDispatchDao.DASession.BeginTransaction();
            try
            {
                foreach (TProjectDispatch o in lst)
                {
                    if (!_TProjectDispatchDao.Update(o))
                    {
                        _TProjectDispatchDao.DASession.RollbackTransaction();
                        return false;
                    }
                }
                _TProjectDispatchDao.DASession.CommitTransaction();
                return true;
            }
            catch
            {
                _TProjectDispatchDao.DASession.RollbackTransaction();
                throw;
            }
        }

        public bool Delete(int o_id)
        {
            return _TProjectDispatchDao.Delete(o_id) > 0;
        }

        public bool DeleteList(IList<TProjectDispatch> lst)
        {
            _TProjectDispatchDao.DASession.BeginTransaction();
            try
            {
                foreach (TProjectDispatch o in lst)
                {
                    if (_TProjectDispatchDao.Delete(o) != 1)
                    {
                        _TProjectDispatchDao.DASession.RollbackTransaction();
                        return false;
                    }
                }
                _TProjectDispatchDao.DASession.CommitTransaction();
                return true;
            }
            catch
            {
                _TProjectDispatchDao.DASession.RollbackTransaction();
                throw;
            }
        }

		public int Count(IDictionary con)
		{
			return _TProjectDispatchDao.Count(con);
		}

        public IList<TProjectDispatch> List(IDictionary con, int pagesize, int page)
        {
            return _TProjectDispatchDao.List(con, pagesize, page);
        }

        public IList<TProjectDispatch> ListAll()
        {
            return _TProjectDispatchDao.List(null);
        }
    }
}